
ticketHub.controller('cacheRefreshCtrls',function($scope,$http){	
	//获取数据列表
	getData();
	//初始化参数
	$scope.postData = {
			originCity : "",
			destinationCity : "",
			flightDateStr : "",
			supplierId : "",												
			beginTimeStr : "",
			endTimeStr : "",
			intervalTime : "",
	};
	//创建
	$scope.create = function(){
		for(var i in $scope.postData){
			if($scope.postData[i]==""){
				layer.msg("请填写所有输入项",{icon:2,time:1000});
				return false;
			}
		}
		var postData = {
				originCity : ($scope.postData.originCity).toUpperCase(),								
				destinationCity : ($scope.postData.destinationCity).toUpperCase(),
				flightDateStr : $scope.postData.flightDateStr,
				supplierId : ($scope.postData.supplierId).toUpperCase(),				
				beginTimeStr : $scope.postData.beginTimeStr+":00",				
				endTimeStr : $scope.postData.endTimeStr+":00",		
				intervalTime : $scope.postData.intervalTime,
		}
		layer.load(3,{shadeClose:true});//加载层；
		$http({
			url:'http://192.168.1.182:8080/task/create',
			method:'post',
			data:postData
		}).success(function(data,header,config,status){	
			layer.closeAll();
			if(data.status==1001){
				layer.msg("创建成功",{icon:1,time:1000},function(){
					getData();	
				});					
			}else{
				layer.alert("创建失败"+data.data);	
			}
			
		}).error(function(data,header,config,status){
			//处理响应失败
			layer.closeAll();	
			layer.alert("请求失败，请检查网络连接")			
		});	
	}
	//开始
	$scope.start = function(item){
		layer.confirm('确定开启此task？', {
			 btn: ['确定','取消'] //按钮
		}, function(){
			  layer.load();
			  $http({
					url:'http://192.168.1.182:8080/task/start',
					method:'get',
					params:{id:item.id}
			  }).success(function(data,header,config,status){	
					layer.closeAll();
					if(data.status==1001){
						layer.msg("开启成功",{icon:1,time:1000},function(){
							getData();
						});							
					}else{
						layer.alert("开启失败"+data.data);	
					}
					
			  }).error(function(data,header,config,status){
					//处理响应失败
					layer.closeAll();	
					layer.alert("请求失败，请检查网络连接")			
			  });	
		});
	}
	//暂停
	$scope.stop = function(item){
		layer.confirm('确定关闭此task？', {
			 btn: ['确定','取消'] //按钮
		}, function(){
			  layer.load();
			  $http({
					url:'http://192.168.1.182:8080/task/stop',
					method:'get',
					params:{id:item.id}
			  }).success(function(data,header,config,status){	
					layer.closeAll();
					if(data.status==1001){
						layer.msg("关闭成功",{icon:1,time:1000},function(){
							getData();
						});							
					}else{
						layer.alert("关闭失败"+data.data);	
					}
					
			  }).error(function(data,header,config,status){
					//处理响应失败
					layer.closeAll();	
					layer.alert("请求失败，请检查网络连接")			
			  });	
		});
	}
	//删除
	$scope.del = function(item){
		layer.confirm('确定删除此task？', {
			 btn: ['确定','取消'] //按钮
		}, function(){
			  layer.load();
			  $http({
					url:'http://192.168.1.182:8080/task/delete',
					method:'get',
					params:{id:item.id}
			  }).success(function(data,header,config,status){	
					layer.closeAll();
					if(data.status==1001){
						layer.msg("删除成功",{icon:1,time:1000},function(){
							getData();
						});							
					}else{
						layer.alert("删除失败"+data.data);	
					}
					
			  }).error(function(data,header,config,status){
					//处理响应失败
					layer.closeAll();	
					layer.alert("请求失败，请检查网络连接")			
			  });	
		});
	}
	
	
	
	
	
	
	
	
	
	
	//获取数据
	function getData(){
		layer.load(3,{shadeClose:true});//加载层；
		$http({
			url:'http://192.168.1.182:8080/task/getAll',
			method:'get',
		}).success(function(data,header,config,status){	
			layer.closeAll();
			if(data.status==1001){
				$scope.task = data.data;
			}else{
				layer.alert("请求失败"+data.data)	
			}
			
		}).error(function(data,header,config,status){
			//处理响应失败
			layer.closeAll();	
			layer.alert("请求失败，请检查网络连接")			
		});	
	}
})
	
	
